package gui.models;

import gui.frames.PlayFrame;

import java.util.Observable;

import common.Fictionator;
import common.enums.AnswerEnum;
import common.interfaces.PlayInterface;
import common.types.Pair;

public class PlayModel extends Observable {

	private Pair<Integer, String> nextQuestion;
	private String guess;
	private boolean isGuessed;
	private boolean isSubmitedGuess;
	private AnswerEnum answer;
	private String enteredActual;
	
	public PlayModel(PlayFrame frame) {
		resetModel();
	}
	
	public void resetModel() {
		guess = null;
		nextQuestion = null;
		isGuessed = false;
		isSubmitedGuess = false;
		answer = null;
		enteredActual = null;
	}
	
	public boolean isGuessed() {
		return isGuessed;
	}

	public void setIsGuessed(boolean isGuessed) {
		this.isGuessed = isGuessed;
		setChanged();
	}

	public Pair<Integer, String> getNextQuestion() {
		return nextQuestion;
	}
	
	public void setNextQuestion(Pair<Integer, String> nextQuestion) {
		this.nextQuestion = nextQuestion;
		setChanged();
	}
	
	public String getGuess() {
		return guess;
	}
	
	public void setGuess(String guess) {
		this.guess = guess;
		setChanged();
	}
	
	public AnswerEnum getAnswer() {
		return answer;
	}
	
	public void setAnswer(AnswerEnum answer) {
		this.answer = answer;
		setChanged();
	}

	public PlayInterface getPlayLogic() {
		return Fictionator.getInstance().getPlayLogic();
	}

	public void setIsSubmitedGuess(boolean isSubmitedGuess) {
		this.isSubmitedGuess = isSubmitedGuess;
		setChanged();
	}

	public boolean isSubmitedGuess() {
		return isSubmitedGuess;
	}
	
	public boolean isCorrectGuess() {
		switch (getAnswer()) {
			case YES:
				return true;
			case NO:
				return false;
		}
		return false;
	}

	public void setEnteredActual(String enteredName) {
		this.enteredActual = enteredName;
		setChanged();
	}
	
	public boolean isEnteredActual() {
		return enteredActual != null && !enteredActual.isEmpty();
	}
	
	public String getActual() {
		return isCorrectGuess() ? guess : enteredActual;
	}
	
}
